//
//  ReversiBoardLineRangeEnumerator.m
//  Reversi
//
//  Created by 成瀬 龍人 on 2/5/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "ReversiBoardLineRangeEnumerator.h"


@implementation ReversiBoardLineRangeEnumerator
- (id)initWithLineRange:(ReversiBoardLineRange*)aLineRange{
	[super init];
	lineRange = aLineRange;
	index = 0;
	return self;
}

- (NSArray*)allObjects{
	NSMutableArray* array = [[NSMutableArray alloc] init];
	for(int i = 0; i < lineRange.numberOfStone; ++i){
		int x = lineRange.startPosition.x + i * lineRange.direction.x;
		int y = lineRange.startPosition.y + i * lineRange.direction.y;
		[array addObject:[[ReversiBoardPosition alloc] initWithInt:x:y]];
	}
	return array;
}

- (id)nextObject{
	if (index < lineRange.numberOfStone){
		int x = lineRange.startPosition.x + index * lineRange.direction.x;
		int y = lineRange.startPosition.y + index * lineRange.direction.y;
		index++;
		return [[ReversiBoardPosition alloc] initWithInt:x:y];
	}
	return nil;
}
@end
